home *** CD-ROM | disk | FTP | other *** search
/ F1 Licenseware / F1 Licenseware - Volume 1.iso / disks / 050a.dms / 050a.adf / TEXTS / chapter05.txt < prev    next >
Text File  |  1992-02-26  |  9KB  |  228 lines

  1.                      The Absolute Beginners Guide To Amos
  2.                     -------------------------------------
  3.                                  Chapter Five
  4.                                 -------------
  5. In this chapter we are going to discover the mysteries of loading a picture
  6. from disk and displaying it on screen. But before we can actually get around
  7. to this there are a few important things you must learn. The first is about
  8. screens and the second is strings. Here we go.
  9.  
  10. SCREENS:
  11. --------
  12. Amos has an excellent range of screen commands where the user can do almost
  13. anything.  We can create custom screens changing the size, amount of colours
  14. width and height and  other things.  We are not going to delve too deeply
  15. here as it will just confuse you.  In keeping with this tutorial I am just
  16. going to explain the minimum amount of commands you need to know about to 
  17. understand how the example program works.
  18.  
  19. There are at least four ways that we can load in a screen from disk, 
  20. I intend to cover three of them in this chapter as pictures play quite a
  21. large part in games as title screens, backgrounds etc.
  22. One way to load a picture is manually, we can press ESCAPE and type in 
  23.  
  24. LOAD IFF "PICTURE NAME",0  
  25. -------------------------
  26. Which will load in a picture to screen 0.  Screen 0 is the screen you are 
  27. looking at and is created by Amos automatically. 
  28. You can create other screens but we will be covering that later too so don`t 
  29. worry about that for now. Also don`t worry about understanding the above 
  30. load command yet I will explain further in a minute. 
  31. Using this method is really only for checking or SPACKING a picture into a 
  32. memory bank which we will also cover later, but I thought I would give it a 
  33. quick mention here to ease you into the idea.
  34.  
  35. The second way to load a screen is from inside your program.  
  36. Let`s say you wish to load a title screen for the start of your game this is
  37. what you could do:
  38.  
  39. HIDE
  40. LOAD IFF"DF0: PICS/SONIC.IFF",0
  41. WAIT KEY: EDIT
  42.  
  43. Yes that is all it is! We could squash all that on to one line if we wanted
  44. to, like this:
  45.  
  46. HIDE:LOAD IFF"DF0: PICS/SONIC.IFF",0: WAIT KEY: EDIT
  47.  
  48. it's not so easy to read but if you know what it does it`s OK.  This is just
  49. a habit I have, I sometimes prefer my programs to be like this as long as it
  50. is not a complex part of the program then it keeps it out of the way, you 
  51. don`t have to do this so don`t worry about it.
  52.  
  53. In nearly any other Amiga programming language loading and displaying an IFF
  54. picture is an absolute nightmare to the beginner so think yourselves lucky,
  55. and thank Francois Lionet, the creator of Amos.
  56.  
  57. OK here is a detailed examination of the above program:
  58.  
  59. HIDE
  60. ----
  61. HIDEs the mouse pointer from the users view.
  62.  
  63. LOADIFF
  64. ------
  65. Tells Amos we want to LOAD an IFF picture file.
  66.  
  67. "DF0:
  68. ----
  69. Tells Amos the drive to use, change this to DF1: if you are using your 
  70. external drive.
  71.  
  72. PICS/SONIC.IFF"
  73. ---------------
  74. Is the name of the picture we want to load and it is stored in the PICS 
  75. drawer on this disk.
  76.  
  77. ,0
  78. --
  79. The screen to load the picture into for displaying, Screen 0 as explained 
  80. earlier is the default screen already created for us by Amos, as screen 0 is 
  81. the actual screen we are looking at we will see the picture displayed 
  82. automatically. If, by mistake you put any other number than 0 then Amos
  83. would report a SCREEN NOT OPENED error. We will be covering SCREEN OPEN soon.
  84.  
  85. WAIT KEY: EDIT
  86. --------------
  87. Look up your notes or see the tips in EXAMPLE5.Amos
  88.  
  89. If you read the above a few times and messed with EXAMPLE5.Amos I think
  90. you will have a good idea of how this all works.
  91.  
  92. I said earlier that we will cover three ways we to load a picture into Amos.
  93.  
  94. Suppose you had written an art program and you had to let the user 
  95. LOAD in any picture he/she wanted.  The above examples would be useless
  96. because we can`t know the name of the file to load.  
  97. The solution is the Amos file selector. But before we can continue I am going
  98. to have to introduce you to the string. The ($) dollar sign, is known in
  99. this case as STRING and $ represents any letter or combination of letters to
  100. hold a variable. Look up your notes on variables.  The difference between the
  101. numerical variable and the $ variable is obvious when you look at the 
  102. following examples:
  103.  
  104. Numerical variables we learnt about earlier:
  105. --------------------------------------------
  106. A
  107. AVARIABLE
  108. F1
  109. TT
  110.  
  111. These can be assigned numbers that can be changed with INC, DEC etc.
  112.  
  113.  
  114. String variables:
  115. -----------------
  116. A$
  117. AVARIABLE$
  118. F1$
  119. TT$
  120.  
  121. These can be assigned text like this:
  122.  
  123. A$="LOTS OF TEXT AND STUFF, EVEN NUMBERS IF YOU LIKE 1234567890" 
  124.  
  125. Remember the PRINT command?  What we were doing, although not realizing it at
  126. the time, was assigning a string of text to tell PRINT what to PRINT, 
  127. in the same way we can assign text to a string variable, which is 
  128. normally inside the familiar quote marks " " If you are having trouble 
  129. wrapping your head around this concept then that makes you a normal human. 
  130. If you understand the string concept from the explanation above alone then 
  131. you are well on your way to stardom.  Right, I am not going to dwell on 
  132. strings for too long as I don`t want to put you off, but you will see why I 
  133. had to mention strings in a moment.
  134.  
  135. Here is how to bring up the Amos file requester so that the user can select
  136. any picture file, load the users selected picture and display it on screen:
  137.  
  138. See EXAMPLE5_1.Amos
  139. -------------------
  140.  
  141. F$=fsel$("*.*","","LOAD A PICTURE")
  142. IF F$="" THEN EDIT
  143. HIDE
  144. LOAD IFF F$,0
  145. WAIT KEY: EDIT
  146.  
  147. Don`t panic, here`s the breakdown:
  148.  
  149.  
  150. F$=fsel$("*.*","","LOAD A PICTURE")
  151. -----------------------------------
  152. Oh no! Look at that first line, it`s not so bad as it looks, honest guv!
  153. The good news is you don`t have to understand exactly how this line works,
  154. all you need to understand is that F$ will hold the exact filename of 
  155. whatever file the user has selected with the mouse. Don`t worry about how 
  156. each part of this line works, it`s irrelevant, except that when you type it 
  157. in it has to be exactly as above, all the quotes commas and brackets need to
  158. be in the right place. Of course you can put in any text at the end of the 
  159. line that you like such as "LOAD A PIC" or "SELECT A PICTURE" or nothing at 
  160. all, like this "". This is two quotes, which signifies an empty string. 
  161. You could also change the first F$ to anything you like, FILESELECT$, FF$, 
  162. WIBBLE$ or ABC$ but you will have to change the F$ in line 4 to be the same.
  163.  
  164. IF F$="" THEN EDIT
  165. ------------------
  166. In English this would sound like:
  167.  
  168. IF the string of text held in F$ is equal to nothing THEN jump to the EDITor.
  169.  
  170. It`s new concept time again. The IF THEN structure is a powerful and 
  171. often used process. If you read the notes in Example4.Amos then this is where
  172. we cover the IF THEN commands. Flip back to Example4.Amos when you
  173. understand it and put your new found knowledge to the test.
  174.  
  175. here are some real life examples of IF THEN:
  176.  
  177. IF the kettle has boiled     THEN switch it off
  178.  
  179. IF it is raining             THEN put hat on
  180.  
  181. IF petrol is low             THEN fill the tank
  182.  
  183. IF F$ equals nothing         THEN jump to editor
  184.  
  185. Just make a note that the IF THEN structure is as follows,
  186.  
  187. IF (do a check on something) THEN (execute something if true)
  188. --                           ----
  189.  
  190. The point is if the IF part (the question if you like) is true the THEN part
  191. of the line will be executed, furthermore if the IF part is false then Amos
  192. will ignore the rest of the line, example:
  193.  
  194. (The kettle isn`t boiling yet)
  195. IF the kettle has boiled       THEN switch it off
  196. continue with program because the IF part was false
  197.  
  198. So getting back to F$. IF F$ does not contain the empty string "" then Amos
  199. will not go to the EDITor but will continue on to the next instruction
  200. which is:
  201.  
  202. HIDE
  203. ----
  204. We are hiding the mouse just to keep things tidy, we didn`t HIDE it earlier
  205. in the program as the user needed to use it to select the file with.
  206.  
  207. LOAD IFF F$,0
  208. -------------
  209. LOAD IFF tells Amos to prepare to LOAD an IFF picture.
  210. F$ holds the name of the file the user has selected.
  211. The 0 is the screen the picture will be loaded into and viewed. 
  212. Screen 0 is the default screen as described earlier in this chapter.
  213.  
  214. WAIT KEY: EDIT
  215. --------------
  216. If all went well and the user selected an IFF file the picture should now be
  217. displayed on your screen, Amos will WAIT for a KEY press then return you to
  218. the EDITor.
  219. If the user selected a non-IFF picture Amos will simply generate an error 
  220. and the program will end. There are ways to stop this happening that we may
  221. cover in a more advanced chapter.
  222.  
  223. Take a look at Example5.Amos and Example5_1.Amos and take a look at the
  224. pictures supplied on this disk, they are inside the PICS drawer.
  225.  
  226.                              End of chapter five
  227.                              ^^^^^^^^^^^^^^^^^^^
  228.